<template>
  <div class="mod-config">
    <el-form :inline="true" :model="dataForm" @keyup.enter.native="getDataList()">


      <el-form-item>
        <el-input v-model="dataForm.servicecode" placeholder="业务标识码" clearable></el-input>
      </el-form-item>
      <el-form-item>
        <el-input v-model="dataForm.serviceno" placeholder="业务件号" clearable></el-input>
      </el-form-item>
      <el-form-item>
        <el-input v-model="dataForm.realtyno" placeholder="不动产登记证明号" clearable></el-input>
      </el-form-item>
            <el-form-item>
        <el-input v-model="dataForm.babsm" placeholder="合并编码" clearable></el-input>
      </el-form-item>

      <el-form-item>
          <el-select v-model="dataForm.state" clearable placeholder="交易状态">
            <el-option
              v-for="item in options"
              :key="item.code"
              :label="item.name"
              :value="item.code">
            </el-option>
          </el-select>
      </el-form-item>

      <el-form-item>
        <el-button type="primary"  @click="getDataList()">本地查询</el-button>
        <el-button v-if="isAuth('bdc:manualyzb:info')" type="primary" @click="printCode()"   :disabled="dataListSelections.length <= 0">批量打印条形码</el-button>
        <el-button v-if="isAuth('bdc:manualyzb:info')" type="primary" @click="printCodePs()"  :disabled="dataListSelections.length <= 0">批量打印品胜条形码(自助)</el-button>

        <el-button v-if="isAuth('bdc:manualyzb:save')" type="primary" @click="yzbHandle()"  >预转本</el-button>
      </el-form-item>
    </el-form>
    <el-table
      :data="dataList"
      border
      v-loading="dataListLoading"
      @selection-change="selectionChangeHandle"
      style="width: 100%;">
      <el-table-column
        type="selection"
        header-align="center"
        align="center"
        width="50">
      </el-table-column>

                  <el-table-column
        prop="btypeTranslate"
        header-align="center"
        align="center"
        label="业务类型">
      </el-table-column>

            <el-table-column
        prop="stateTranslate"
        header-align="center"
        align="center"
        label="审核状态">
      </el-table-column>

      <el-table-column
        prop="sendtime"
        header-align="center"
        align="center"
        label="更新时间">
      </el-table-column>

      <el-table-column
        prop="servicecode"
        header-align="center"
        align="center"
        label="业务标识码">
      </el-table-column>

      <el-table-column
        prop="realtyno"
        header-align="center"
        align="center"
        label="不动产登记证明号">
      </el-table-column>

      <el-table-column
        prop="bdbzqse"
        header-align="center"
        align="center"
        label="被担保债权数额">
      </el-table-column>
      <el-table-column
        prop="zwlxqssj"
        header-align="center"
        align="center"
        label="债务履约起始时间">
      </el-table-column>
      <el-table-column
        prop="zwlxjssj"
        header-align="center"
        align="center"
        label="债务履约结束时间">
      </el-table-column>

      <el-table-column
        prop="isdygh"
        header-align="center"
        align="center"
        label="带抵押过户标识">
      </el-table-column>

      <el-table-column
        prop="serviceno"
        header-align="center"
        align="center"
        label="业务件号">
      </el-table-column>
      <el-table-column
        prop="slh"
        header-align="center"
        align="center"
        label="受理号">
      </el-table-column>

      <el-table-column
        fixed="left"
        header-align="center"
        align="center"
        width="150"
        label="操作">
        <template slot-scope="scope">
          <el-button type="text" v-if="(scope.row.state=='51'  || scope.row.state=='54') && isAuth('bdc:manualyzb:upload')"  size="small"  
            @refreshDataList="getDataList"  @click="toUploadHandle(scope.row.seqno, scope.row.btype)">资料上传</el-button>

          <el-button type="text" v-if="scope.row.state=='52' && isAuth('bdc:manualyzb:commit')"  size="small"  
            @refreshDataList="getDataList"  @click="toSubmitHandle(scope.row.seqno, scope.row.btype)">审核提交</el-button>
          <el-button type="text" v-if="scope.row.state=='11' && isAuth('bdc:manualyzb:save')" size="mini"    @refreshDataList="getDataList"  @click="reNewHandle(scope.row.seqno)">重新提交</el-button>
          <el-button type="text" v-if="(scope.row.state=='00' || scope.row.state=='53') && isAuth('bdc:manualyzb:save') " size="mini"    @refreshDataList="getDataList"  @click="toCompleteHandle(scope.row.seqno, scope.row.btype)">完善登记</el-button>
          <el-button type="text" size="mini"  @click="beforeprocview(scope.row.seqno)">查看进度</el-button>

        <el-button type="text" size="mini" v-if="scope.row.state=='25'" 
             @click="certinfoHandle(scope.row.bdcno, scope.row.region, scope.row.servicecode, scope.row.serviceno, scope.row.realtyno)">电子证明查询</el-button>


                  <el-button type="text" v-if="scope.row.slh" size="mini"    @refreshDataList="getDataList"  @click="printCodePs(scope.row.seqno)">条形码(自助)</el-button> 
          <el-button type="text" size="mini" @click="detailHandle(scope.row.seqno)">显示详情</el-button>

        </template>
      </el-table-column>
      
    </el-table>
    <el-pagination
      @size-change="sizeChangeHandle"
      @current-change="currentChangeHandle"
      :current-page="pageIndex"
      :page-sizes="datepicker.pageOptions"
      :page-size="pageSize"
      :total="totalPage"
      layout="total, sizes, prev, pager, next, jumper">
    </el-pagination>
    <!-- 弹窗, 新增 / 修改 -->

    <bdc-dy-query v-if="dyQueryVisible" ref="dyQuery" @refreshDataList="toyzbnew" ></bdc-dy-query>    
    <yzb-new v-if="yzbNewVisible" ref="yzbNew"   @refreshDataList="getDataList" ></yzb-new> 
    <procview v-if="procviewVisible" ref="procview"   @refreshDataList="getDataList" ></procview>
    <yzb-register-detail v-if="yzbRegisterDetailVisible" ref="yzbRegisterDetail"   @refreshDataList="getDataList" ></yzb-register-detail> 
    <print-bar-code v-if="printBarCodeVisible" ref="printBarCode"   @refreshDataList="getDataList" ></print-bar-code> 
    <bdc-cert-info  v-if="certinfoVisible" ref="bdcCertInfo" @refreshDataList="getDataList"></bdc-cert-info>
    
  </div>



</template>

<script>

  import BdcDyQuery from './bdc-dy-query'
  import YzbNew from './yzb-register-new'
  import Procview from './bdcprocview'
  import YzbRegisterDetail from './yzb-register-detail'  
  import PrintBarCode from './bdc-printbarcode' 
  import { printPs}   from '@/assets/js/printbarcode.js' 
  import BdcCertInfo from './bdccertinfo-add-or-update'
  export default {
    data () {
      return {
        options: [],
        dataForm: {
          key: ''
        },
        dataList: [],
        pageIndex: 1,
        pageSize: 10,
        totalPage: 0,
        dataListLoading: false,
        dataListSelections: [],
        dyQueryVisible: false,
        yzbNewVisible: false,
        procviewVisible: false,
        yzbRegisterDetailVisible: false,
        printBarCodeVisible: false,
        certinfoVisible: false
      }
    },
    components: {
      BdcDyQuery,
      YzbNew,
      Procview,
      YzbRegisterDetail,
      PrintBarCode,
      BdcCertInfo
    },
    activated () {
      this.getDataList()
      this.initOptions()
    },
    methods: {
      initOptions(){
          this.$http({
            url: this.$http.adornUrl(`/bdc/bdcstateinfo/item/list`),
            method: 'get',
            params: this.$http.adornParams()
          }).then(({data}) => {
            this.options = data.list
          })
      },

      certinfoHandle (bdcno, region, servicecode, serviceno, realtyno) {
        this.certinfoVisible = true
        this.$nextTick(() => {
          this.$refs.bdcCertInfo.init(-1, bdcno, region, servicecode)
        })
      },
        checkBeforePrint(){
          for (var i = 0; i < this.dataListSelections.length; i++){
            var data = this.dataListSelections[i]
            if (!data.slh){
              return false
            }
          }
          return true
        },
        printCode(){
            if (!this.checkBeforePrint()){
              this.$message.error("只能打印有受理号的记录")
              return
            }

            var ids = this.dataListSelections.map(item => {
              return item.seqno
            })
            if (ids.length == 0){
              this.$message.error("请勾选待打印数据")
              return ;
            }
            this.printBarCodeVisible = true
            this.$nextTick(() => {
              this.$refs.printBarCode.init(ids)
            })
        },

        printCodePs(id){

          if (!this.checkBeforePrint()){
              this.$message.error("只能打印有受理号的记录")
              return
            }

          var ids = id ? [id] : this.dataListSelections.map(item => {
            return item.seqno
          })

          if (ids.length == 0){
            this.$message.error("请勾选待打印数据")
            return ;
          }
                
          printPs(ids, this)
         
      },

      beforeprocview(id){
        this.$http({
            url: this.$http.adornUrl(`/bdc/bdcprocview/procview/` + id),
            method: 'get',
            params: this.$http.adornParams()
          }).then(({data}) => {
            if (data && data.code === 0) {

                this.procviewHandle(data.seqno, data.btype, data.servicecode, data.zl, data.seRegion)

            }
            else{
              this.$message.error(data.msg)
            }
          }).catch(err => {
            this.$message.error("系统内部错误")
            console.error(err);            
        }); 
      },

      procviewHandle(seqno, btype, servicecode, zl, seRegion){
        this.procviewVisible = true
        this.$nextTick(() => {
          this.$refs.procview.init(seqno, btype, servicecode, zl, seRegion)
        })
      },

      yzbHandle () {
        this.dyQueryVisible = true
        this.$nextTick(() => {
          this.$refs.dyQuery.init(-2)
        })
      },

      toUploadHandle(id){
          this.yzbNewVisible = true
          this.$nextTick(() => {
              this.$refs.yzbNew.init(51, id)
          })
      },
      
      toSubmitHandle(id){
          this.yzbNewVisible = true
          this.$nextTick(() => {
              this.$refs.yzbNew.init(52, id)
          })
      },

      toCompleteHandle(id){
          this.yzbNewVisible = true
          this.$nextTick(() => {
              this.$refs.yzbNew.init(1, id)
          })
      },

      detailHandle(id){
          this.yzbRegisterDetailVisible = true
          this.$nextTick(() => {
              this.$refs.yzbRegisterDetail.init(1, id)
          })
      },

      reNewHandle(id){
          this.yzbNewVisible = true
          this.$nextTick(() => {
              this.$refs.yzbNew.init(2, id)
          })
      },

      toyzbnew(obankid, ywjh, region){
          this.yzbNewVisible = true
          this.$nextTick(() => {
            this.$refs.yzbNew.init(0, obankid, ywjh, region)
          })
      },

      // 获取数据列表
      getDataList () {
        this.dataListLoading = true
        this.$http({
          url: this.$http.adornUrl('/bdc/manualyzb/list'),
          method: 'get',
          params: this.$http.adornParams({
            'page': this.pageIndex,
            'limit': this.pageSize,
            'key': this.dataForm.key
          })
        }).then(({data}) => {
          if (data && data.code === 0) {
            this.dataList = data.page.list
            this.totalPage = data.page.totalCount
          } else {
            this.dataList = []
            this.totalPage = 0
          }
          this.dataListLoading = false
        })
      },
      // 每页数
      sizeChangeHandle (val) {
        this.pageSize = val
        this.pageIndex = 1
        this.getDataList()
      },
      // 当前页
      currentChangeHandle (val) {
        this.pageIndex = val
        this.getDataList()
      },
      // 多选
      selectionChangeHandle (val) {
        this.dataListSelections = val
      }

    }
  }
</script>
<style lang="scss">
body .el-table th.gutter{
    display: table-cell!important;

}
</style>